<template>
  <view class="setting-container" :style="{height: `${windowHeight}px`}">
    <view class="menu-list">
      <view class="list-cell list-cell-arrow" @click="handleToPwd">
        <view class="menu-item-box">
          <view class="iconfont icon-password menu-icon"></view>
          <view>修改密码</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="handleToUpgrade">
        <view class="menu-item-box">
          <view class="iconfont icon-refresh menu-icon"></view>
          <view>检查更新</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="handleCleanTmp">
        <view class="menu-item-box">
          <view class="iconfont icon-clean menu-icon"></view>
          <view>清理缓存</view>
        </view>
      </view>
    </view>
    <view class="cu-list menu">
      <view class="cu-item item-box">
        <view class="content text-center" @click="handleLogout">
          <text class="text-black">退出登录</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        windowHeight: uni.getSystemInfoSync().windowHeight
      }
    },
    methods: {
      handleToPwd() {
        this.$tab.navigateTo('/pages/mine/pwd/index')
      },
      handleToUpgrade() {
        this.$modal.showToast('模块建设中~')
      },
      handleCleanTmp() {
        this.$modal.showToast('模块建设中~')
      },
      handleLogout() {
        // 弹出密码输入框
        uni.showModal({
          title: '退出登录',
          content: '请输入退出密码',
          editable: true,
          placeholderText: '请输入密码',
          success: (res) => {
            if (res.confirm) {
              const password = res.content
              if (password === '921020') {
                // 密码正确，执行退出登录
                this.$modal.confirm('确定注销并退出系统吗？').then(() => {
                  this.$store.dispatch('LogOut').then(() => {
                    // 清除用户信息
                    this.$store.commit('SET_USER', null)
                    this.$store.commit('SET_TOKEN', '')
                    this.$store.commit('SET_ROLES', [])
                    this.$store.commit('SET_PERMISSIONS', [])
                  }).finally(() => {
                    // 跳转到登录页面
                    this.$tab.reLaunch('/pages/login')
                  })
                })
              } else {
                // 密码错误
                this.$modal.msgError('密码错误，无法退出登录')
              }
            }
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .page {
    background-color: #f8f8f8;
  }

  .item-box {
    background-color: #FFFFFF;
    margin: 30rpx;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 10rpx;
    border-radius: 8rpx;
    color: #303133;
    font-size: 32rpx;
  }
</style>
